import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'
import PluginView from '@/views/layout/PluginView'

import customize from './customize'
import ems from './ems'
import tpm from './tpm'
import esop from './esop'
import masterdata from './masterdata'
import mes from './mes'
import platform from './platform'
import quality from './quality'
import winclient from './winclient'
import wms from './wms'
import orders from './orders'
import iqc from './iqc'
import mass from './mass'

/**
 * 注意三级及以下菜单需要使用 SubLayout 无法 keeps-alive 缓存
 */

export const constantRouterMap = [
  {
    path: '/',
    redirect: '/home/welcome',
  },
  {
    path: '/login',
    component: () => import('@/views/platform/login/index'),
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':path*',
        component: () => import('@/views/platform/redirect/index'),
      },
    ],
  },
  {
    path: '/401',
    component: () => import('@/views/platform/errorPage/401'),
    name: '401',
  },
  {
    path: '/404',
    name: '404',
    meta: { title: '错误页' },
    component: () => import('@/views/platform/errorPage/404'),
  },
  {
    path: '/home',
    name: 'home',
    component: Layout,
    meta: { title: '首页', icon: 'home' },
    children: [
      {
        path: 'welcome',
        component: () => import('@/views/platform/home/welcome'),
        name: 'welcome',
        meta: { title: '欢迎页' },
      },
    ],
  },
  {
    path: '/homeClient',
    name: 'homeClient',
    component: () => import('@/views/platform/home/client'),
    meta: { title: '首页', noCache: false },
  },
  {
    path: '/devTest',
    component: Layout,
    children: [
      {
        path: 'icon',
        component: () => import('@/views/devTest/svg-icons'),
        name: 'exampleIcon',
        meta: { title: '图标' },
      },
      {
        path: 'testPage',
        component: () => import('@/views/devTest/testPage'),
        name: 'testPage',
        meta: { title: '开发测试页' },
      },
      {
        path: 'pluginPage',
        component: PluginView,
        name: 'testPluginPage',
        meta: { title: '定制开发示例' },
      },
    ],
  },
]

export const asyncRouterMap = [
  customize,
  ems,
  tpm,
  esop,
  masterdata,
  mes,
  platform,
  quality,
  wms,
  orders,
  iqc,
  mass,
  ...winclient,
]

export const noPageRoute = { path: '*', redirect: { name: '404' } }

export default new Router({
  routes: constantRouterMap,
  mode: 'hash',
  scrollBehavior: () => ({ y: 0 }),
})
